package TankGame06;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Scanner;

public class TankGameFrame extends JFrame {
    MyPanel myPanel = null;
    Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        new TankGameFrame();
    }

    public TankGameFrame() throws HeadlessException, IOException {
        System.out.println("请输入选择 1:开始新游戏 2:继续上局游戏");
        String key = scanner.next();
        myPanel = new MyPanel(key);
        new Thread(myPanel).start();//启动线程
        this.add(myPanel);
        this.setSize(1200,750);//设置窗口宽高
        this.addKeyListener(myPanel);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//点击×退出
        this.setVisible(true);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                try {
                    Recorder.savehitEnemyNum();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                System.exit(0);
            }
        });
    }
}
